<template>
  <div>
    <Row align="middle" justify="center">
      <Col>
        <h1 style="text-align: center; ">买车信息</h1>
      </Col>
    </Row>
    <Row :gutter="250">
      <Col span="6" offset="10">
        <Button type="info" @click="add(clientId, orderTypeId)">新增</Button>
      </Col>
    </Row>
    <Card
      v-for="item in carBuy"
      style="width:600px;margin: 10px;display: inline-block;"
    >
	<div @click="carbuyDetail(item.cbId)">
		<h3>
		  <a href="proinfo.html">{{ item.title }}</a>
		</h3>
		<div class="pra-fang">要求：{{ item.details }}</div>
		<div class="pra-fang">发布时间：{{ item.ct }}</div>
		<div class="pra-fang">发布人：{{ item.personName }}</div>
		<Button type="info" @click="change(item.cbId)">修改信息</Button>
		<Button type="error" @click="remove(item.cbId)" style="margin-left: 10px;"
		  >删除</Button
		>
	</div>
    </Card>
    <div class="clears"></div>
        <div class="page">
          <Page
            :page-size="pageSize"
            @on-change="pageSearch"
            :total="total"
            :current="currentPage"
          />
        </div>
    <!-- <div class="width1190">
			<div class="pro-left">
				<dl 
                  <dt><a href="proinfo.html"><img :src="item.imgUrl" width="286" height="188"></a></dt>
					<dd>
						
					</dd>
				</dl>
			</div>
		</div> -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentUser: {},
      clientId: '',
      carBuy: [],
      orderTypeId: 7,
	  currentPage: null,
	  pageSize: null,
	  total:null,
      orderInfo: {},
    }
  },
  methods: {
    carbuyDetail:function(cbId){
		this.$router.push({
			name:'car_buy_detail',
			params:{
				cbId
			}
		})
	},
    add: function(clientId, orderTypeId) {      
      this.$router.push({
        name: 'add_car_buy',
        params: {
          
        },
      })
    },
	pageSearch: function(changedPage) {
	  this.$data.currentPage = changedPage
	  this.search(changedPage)
	},
    search: function(current) {
      this.http
        .get({
          url: '/car-buy-vo/page',
          param: { 
		  			  clientId: this.$data.clientId,
		  			  pageSize: this.$data.pageSize,
		  			  currentPage: current,
				},
        })
        .then((data) => {
			this.$data.pageSize = data.size,
			this.$data.currentPage = data.current,
			this.$data.total = data.total,
          this.$data.carBuy = data.records
          console.log(data)
        })
    },
    change: function(cbId) {
      console.log(cbId)
      this.$router.push({
        name: 'update_car_buy',
        params: {
          cbId,
        },
      })
    },
    remove: function(cbId) {
      this.http
        .delete({
          url: '/car-buy-vo/info',
          param: {
            cbId,
          },
        })
        .then((data) => {
          this.message.info('删除成功')
          this.search(1)
        })
    },
  },
  created() {
    this.$data.currentUser = JSON.parse(sessionStorage.getItem('CURRENT'))
    this.$data.clientId = this.$data.currentUser.client.clientId
    this.search(1)
  },
  beforeRouteLeave(to, from, next) {
    this.$destroy() //手动销毁当前页面
    next()
  },
}
</script>

<style></style>
